
var app = getApp();
var hostURL = app.globalData1.hostURL;
var ID = app.globalData2.userid;
Page({
  data: {
    userInfo: {},
    id: '',

  },
  onLoad: function () {
    if (app.globalData2.hasLogin) {
      let userInfo = wx.getStorageSync('userInfo');
      this.setData({
        userInfo: userInfo,
      });

    }
  },


  formSubmit: function (e) {
    var info = e.detail.value;
    // var Id=e.detail.value
    if (!info.nickname || !info.tel) {
      wx.showToast({
        title: '输入为空',
        icon: 'loading',
        duration: 1000
      })
    } else {
      console.log(info);
      this.modify(info)
    }
  },
  modify: function (info) {
    let that = this;
    that.data.userInfo.nickname = info.nickname;
    that.data.userInfo.phone = info.tel;
    that.data.userInfo.realname = info.realname1

    wx.getStorageSync("userInfo").id
    console.log(wx.getStorageInfoSync("userInfo").id)

    wx.request({
      url: hostURL + "sharedplatform-web/user/alterUser.action",
      data: {
        userId: wx.getStorageSync("userInfo").id,
        phone: info.tel,
        nickName: info.nickname,
        realName: info.realname1,
      },
      method: 'get',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        var userInfo
        console.log(res.data.alterUser)
        if (res.data.errno == 0) {
          that.setData({
            userInfo: res.data.alterUser,
          })
          wx.setStorageSync('userInfo', res.data.alterUser);
          wx.switchTab({
            url: '../myinfo/myinfo',
            success: function (e) {
              var page = getCurrentPages().pop();
              if (page == undefined || page == null) return;
              page.onLoad()
            }
          });
          wx.showToast({
            title: '修改成功 ',
          })
        }
        else {
          wx.showToast({
            title: '修改失败 ',
          })
        }
      },

    })
  }

})
